package Inner_Class;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86184
 * Date: 2023-02-11
 * Time: 9:41
 */
class OuterClass{  //外部类
    public int data1=1;
    int data2=2;
    private int data3=3;

    /**
     * 实例内部类
     * 1.如何获取 实例内部类的对象？
     *      OuterClass.InnerClass innerClass=outerClass.new InnerClass();
     * 2.实例内部类中不能有静态的成员变量，非要定义，那么只能是被static final修饰
     * 3.在实例内部类当中，如何访问外部类当中，相同变量名的成员变量？
     *      OuterClass.this.data1
     */
    class InnerClass{  //内部类
        public int data1=111;
        public int data4=4;
        int data5=5;
        int data6=6;
        public static final int data7=7;
        public void func(){
            System.out.println("InnerClass::func");
            //访问外部类相同变量名的成员变量
            System.out.println(OuterClass.this.data1);
            OuterClass outClass1=new OuterClass();
            System.out.println(outClass1.data1);

            System.out.println(data1);  //内部类可以访问外部类的成员
            System.out.println(data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
            System.out.println(data7);
        }
    }
    public void fun(){
        System.out.println("OuterClass::fun");
        final int SIZE=10;//定义常量，常量是在程序编译是确定的，一旦初始化，就不能被修改
        //SIZE=20;   会报错
    }
}



public class Instance_Internal_Class {
    public static void main(String[] args) {
        OuterClass outerClass=new OuterClass();
        OuterClass.InnerClass innerClass=outerClass.new InnerClass();
        innerClass.func();
    }

}
